require("../game.js")
var window = $global.window;
var document = window.document;
var XMLHttpRequest = window.XMLHttpRequest;
var Laya = window.Laya;
var Laya3D = window.Laya3D;
"use strict";

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

(function () {
  'use strict';
  /**This class is automatically generated by LayaAirIDE, please do not make any modifications. */

  var GameConfig =
  /*#__PURE__*/
  function () {
    function GameConfig() {
      _classCallCheck(this, GameConfig);
    }

    _createClass(GameConfig, null, [{
      key: "init",
      value: function init() {
        //注册Script或者Runtime引用
        var reg = Laya.ClassUtils.regClass;
      }
    }]);

    return GameConfig;
  }();

  GameConfig.width = 640;
  GameConfig.height = 1136;
  GameConfig.scaleMode = "fixedwidth";
  GameConfig.screenMode = "none";
  GameConfig.alignV = "top";
  GameConfig.alignH = "left";
  GameConfig.startScene = "";
  GameConfig.sceneRoot = "";
  GameConfig.debug = false;
  GameConfig.stat = false;
  GameConfig.physicsDebug = false;
  GameConfig.exportSceneToJson = true;
  GameConfig.init();
  var ConstStrings = {
    pageTitle: "拼出你找到的6双AJ鞋",
    selectedViewItemBg: "res/scene/select_item_bg.png",
    candidateSelectedImg: "res/scene/shipin.png",
    candidateImgDatas: [{
      id: "candidateImg-0",
      // src: "res/scene/shoes/shoe(0).png"
      src:"https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/starbucks2/pic-nogrid/10.png"
    }, {
      id: "candidateImg-1",
      // src: "res/scene/shoes/shoe(1).png"
      src:"https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/starbucks2/pic-nogrid/11.png"
    }, {
      id: "candidateImg-2",
      // src: "res/scene/shoes/shoe(2).png"
      src:"https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/starbucks2/pic-nogrid/12.png"
    }, {
      id: "candidateImg-3",
      // src: "res/scene/shoes/shoe(3).png"
      src:"https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/starbucks2/pic-nogrid/13.png"
    }, {
      id: "candidateImg-4",
      // src: "res/scene/shoes/shoe(4).png"
      src:"https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/starbucks2/pic-nogrid/14.png"
    }, {
      id: "candidateImg-5",
      // src: "res/scene/shoes/shoe(5).png"
      src:"https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/starbucks2/pic-nogrid/15.png"
    }, {
      id: "candidateImg-6",
      // src: "res/scene/shoes/shoe(6).png"
      src:"https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/starbucks2/pic-nogrid/16.png"
    }, {
      id: "candidateImg-7",
      src: "res/scene/shoes/shoe(7).png"
    }, {
      id: "candidateImg-8",
      src: "res/scene/shoes/shoe(8).png"
    }, {
      id: "candidateImg-9",
      src: "res/scene/shoes/shoe(9).png"
    }, {
      id: "candidateImg-10",
      src: "res/scene/shoes/shoe(10).png"
    }, {
      id: "candidateImg-11",
      src: "res/scene/shoes/shoe(11).png"
    }, {
      id: "candidateImg-12",
      src: "res/scene/shoes/shoe(13).png"
    }]
  };

  var SelectItemView =
  /*#__PURE__*/
  function (_Laya$Box) {
    _inherits(SelectItemView, _Laya$Box);

    function SelectItemView() {
      var _this;

      _classCallCheck(this, SelectItemView);

      _this = _possibleConstructorReturn(this, _getPrototypeOf(SelectItemView).call(this));
      var Image = Laya.Image;
      _this.WID = (Laya.stage.width - 100) / 6;
      _this.HEI = _this.WID;

      _this.size(_this.WID, _this.HEI); // 背景img


      _this.bgImg = new Image();

      _this.bgImg.size(_this.WID, _this.HEI);

      _this.addChild(_this.bgImg); // 前景img


      _this.srcImg = new Image();

      _this.srcImg.size(_this.WID * 0.5, _this.HEI * 0.5);

      _this.addChild(_this.srcImg);

      _this.srcImg.pivot(_this.WID * 0.5 * 0.5, _this.HEI * 0.5 * 0.5);

      _this.srcImg.pos(_this.WID * 0.5, _this.HEI * 0.5);

      _this.setBgImg(ConstStrings.selectedViewItemBg);

      return _this;
    }

    _createClass(SelectItemView, [{
      key: "setBgImg",
      value: function setBgImg(src) {
        this.bgImg.skin = src;
      }
    }, {
      key: "setSrcImg",
      value: function setSrcImg(src) {
        this.srcImg.skin = src;
        this.setBgImg(ConstStrings.selectedViewItemBg);
      }
    }]);

    return SelectItemView;
  }(Laya.Box);

  var CandidateItemView =
  /*#__PURE__*/
  function (_Laya$Box2) {
    _inherits(CandidateItemView, _Laya$Box2);

    function CandidateItemView() {
      var _this2;

      _classCallCheck(this, CandidateItemView);

      _this2 = _possibleConstructorReturn(this, _getPrototypeOf(CandidateItemView).call(this));
      var Image = Laya.Image;
      _this2.WID = (Laya.stage.width - 100) / 3.;
      _this2.HEI = _this2.WID;

      _this2.size(_this2.WID, _this2.HEI); // 前景img


      _this2.srcImg = new Image();

      _this2.srcImg.size(_this2.WID * 0.75, _this2.HEI * 0.75);

      _this2.addChild(_this2.srcImg);

      _this2.srcImg.pivot(_this2.WID * 0.75 * 0.5, _this2.HEI * 0.75 * 0.5);

      _this2.srcImg.pos(_this2.WID * 0.5, _this2.HEI * 0.5);

      _this2.selectImg = new Image();

      _this2.selectImg.size(_this2.WID * 0.2, _this2.WID * 0.2);

      _this2.addChild(_this2.selectImg);

      _this2.selectImg.pos(_this2.WID * (0.75 - 0.2), _this2.WID * 0.2);

      _this2.selectImg.skin = ConstStrings.candidateSelectedImg;
      return _this2;
    }

    _createClass(CandidateItemView, [{
      key: "setSrcImg",
      value: function setSrcImg(src) {
        this.srcImg.skin = src;
      }
    }, {
      key: "isSelectImgVisible",
      value: function isSelectImgVisible(e) {
        this.selectImg.visible = e;
      }
    }]);

    return CandidateItemView;
  }(Laya.Box);

  var Main =
  /*#__PURE__*/
  function () {
    function Main() {
      _classCallCheck(this, Main);

      this.selectedDatas = [{}, {}, {}, {}, {}, {}];
      this.selectedDataViews = [];
      this.selectedViewsNum = 6;
      this.viewSelectList = null;
      this.viewCandidateList = null; //根据IDE设置初始化引擎		

      if (window["Laya3D"]) Laya3D.init(GameConfig.width, GameConfig.height);else Laya.init(GameConfig.width, GameConfig.height, Laya["WebGL"]);
      Laya["Physics"] && Laya["Physics"].enable();
      Laya["DebugPanel"] && Laya["DebugPanel"].enable();
      Laya.stage.scaleMode = GameConfig.scaleMode;
      Laya.stage.screenMode = GameConfig.screenMode; // Laya.stage.alignV = GameConfig.alignV;
      Laya.TBMiniAdapter.baseDir = "";

      // Laya.stage.alignH = GameConfig.alignH;

      Laya.stage.alignV = Laya.Stage.ALIGN_MIDDLE;
      Laya.stage.alignH = Laya.Stage.ALIGN_CENTER; //兼容微信不支持加载scene后缀场景

      Laya.URL.exportSceneToJson = GameConfig.exportSceneToJson; //打开调试面板（通过IDE设置调试模式，或者url地址增加debug=true参数，均可打开调试面板）

      if (GameConfig.debug || Laya.Utils.getQueryString("debug") == "true") Laya.enableDebugPanel();
      if (GameConfig.physicsDebug && Laya["PhysicsDebugDraw"]) Laya["PhysicsDebugDraw"].enable();
      if (GameConfig.stat) Laya.Stat.show();
      Laya.alertGlobalError(true); //激活资源版本控制，version.json由IDE发布功能自动生成，如果没有也不影响后续流程

      Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.onVersionLoaded), Laya.ResourceVersion.FILENAME_VERSION);
      this.initScene();
    }

    _createClass(Main, [{
      key: "onVersionLoaded",
      value: function onVersionLoaded() {
        //激活大小图映射，加载小图的时候，如果发现小图在大图合集里面，则优先加载大图合集，而不是小图
        Laya.AtlasInfoManager.enable("fileconfig.json", Laya.Handler.create(this, this.onConfigLoaded));
      }
    }, {
      key: "onConfigLoaded",
      value: function onConfigLoaded() {
        //加载IDE指定的场景
        GameConfig.startScene && Laya.Scene.open(GameConfig.startScene);
      }
    }, {
      key: "initScene",
      value: function initScene() {
        Laya.stage.bgColor = "#232628";
        var pageTitleView = new Laya.Text();
        pageTitleView.text = ConstStrings.pageTitle; //设置文本颜色

        pageTitleView.color = "#ffffff"; //设置文本字体
        // pageTitleView.font = "Ya Hei";
        //设置字体大小

        pageTitleView.fontSize = 32; //设置文本区背景

        pageTitleView.bgColor = "#c30c30"; //设置文本框的颜色

        pageTitleView.borderColor = "#23cfcf"; //设置粗体、斜体

        pageTitleView.bold = true; //设置斜体

        pageTitleView.italic = true;
        pageTitleView.width = 640;
        pageTitleView.height = 40;
        pageTitleView.pos(0, 50);
        pageTitleView.align = "center";
        pageTitleView.valign = "middle";
        Laya.stage.addChild(pageTitleView);
        this.initSelectedBox();
        this.initCandidateBox();
      }
    }, {
      key: "initSelectedBox",
      value: function initSelectedBox() {
        this.viewSelectList = new Laya.List();
        Laya.stage.addChild(this.viewSelectList);
        this.viewSelectList.itemRender = SelectItemView;
        this.viewSelectList.repeatX = this.selectedViewsNum;
        this.viewSelectList.repeatY = 1;
        this.viewSelectList.x = 50; // this.viewSelectList.y = (Laya.stage.height - HEI * list.repeatY) / 2;

        this.viewSelectList.y = 100;
        /**
         * 选中列表更新
         * @param {*} cell 
         * @param {*} index 
         */

        var updateItem = function updateItem(cell, index) {
          console.log("updateItem " + index);
          cell.setSrcImg(cell.dataSource.src);
        };
        /**
         * 选中列表中item被选中
         * @param {*} index 
         */


        var onSelect = function onSelect(index) {
          console.log("当前选择的索引：" + index);
        };

        this.viewSelectList.selectHandler = new Laya.Handler(this, onSelect);
        this.viewSelectList.renderHandler = new Laya.Handler(this, updateItem);
        this.viewSelectList.array = this.selectedDatas;
      }
    }, {
      key: "initCandidateBox",
      value: function initCandidateBox() {
        this.viewCandidateList = new Laya.List();
        Laya.stage.addChild(this.viewCandidateList);
        this.viewCandidateList.itemRender = CandidateItemView;
        this.viewCandidateList.repeatX = 4;
        this.viewCandidateList.repeatY = 3;
        this.viewCandidateList.selectEnable = true;
        this.viewCandidateList.hScrollBarSkin = ""; // this.viewCandidateList.vScrollBarSkin = "";
        // this.viewCandidateList.y = (Laya.stage.height - HEI * list.repeatY) / 2;

        this.viewCandidateList.y = 300;
        /**
         * 选中列表更新
         * @param {*} cell 
         * @param {*} index 
         */

        var updateItem = function updateItem(cell, index) {
          // console.log("updateItem " + index)
          cell.setSrcImg(cell.dataSource.src);
          cell.isSelectImgVisible(cell.dataSource.isSelected);
        };
        /**
         * 选中列表中item被选中
         * @param {*} index 
         */


        var onSelect = function onSelect(e, index) {
          if (e.type != "mouseup") return;
          var tempCell = this.viewCandidateList.getCell(index);

          if (!tempCell.dataSource.isSelected && this.selectedDatas.length >= 12) {
            // this.showWarnDialog("");
            window.showWarnAlert("已选中6双鞋。");
            return;
          }

          tempCell.dataSource.isSelected = !tempCell.dataSource.isSelected;
          if (this.viewCandidateList.selectedIndex == index) tempCell.isSelectImgVisible(tempCell.dataSource.isSelected); // let isInSelectedList = 

          var temp = this.selectedDatas.findIndex(function (obj) {
            return obj.id == tempCell.dataSource.id;
          });
          var isExit = false;
          if (temp >= 0) isExit = true;
          console.log(isExit);

          if (tempCell.dataSource.isSelected) {
            if (!isExit) this.selectedDatas.unshift(tempCell.dataSource);
          } else {
            if (isExit) this.selectedDatas.splice(temp, 1);
          }

          this.viewSelectList.refresh();
          console.log(this.selectedDatas.toString());
        };

        this.viewCandidateList.mouseHandler = new Laya.Handler(this, onSelect);
        this.viewCandidateList.renderHandler = new Laya.Handler(this, updateItem);
        this.viewCandidateList.array = ConstStrings.candidateImgDatas;
      }
    }, {
      key: "showWarnDialog",
      value: function showWarnDialog(str) {
        // const 
        // Dialog = Laya.Dialog,
        // Image = Laya.Image,
        // Button = Laya.Button;
        var DIALOG_WIDTH = 220,
            DIALOG_HEIGHT = 275,
            CLOSE_BTN_WIDTH = 43,
            CLOSE_BTN_PADDING = 5;
        var dialog = new Laya.Dialog();
        var bg = new Laya.Image(ConstStrings.selectedViewItemBg);
        dialog.addChild(bg);
        var button = new Laya.Button(ConstStrings.candidateSelectedImg);
        button.name = Laya.Dialog.CLOSE;
        button.pos(DIALOG_WIDTH - CLOSE_BTN_WIDTH - CLOSE_BTN_PADDING, CLOSE_BTN_PADDING);
        dialog.addChild(button);
        dialog.dragArea = "0,0," + DIALOG_WIDTH + "," + DIALOG_HEIGHT;
        dialog.show();
      }
    }]);

    return Main;
  }(); //激活启动类


  new Main();
})();